The problem is the exercise i use read from text file, so i used getline to get the string line. How can i use strtok( char * c, const char * ch)?Code:#include <cstdlib> #include <iostream> #include <string> using namespace std; int main() { string line = "Today! I'm very-tired "; // if i do like this, the system will hault and Windows error msg appear about the error char str[] = ""; // if i use char str[] = "Today! I'm very-tired " every thing is fine strcpy(str, line.c_str()); char* new_word; int total=0; new_word = strtok(str, "-.,;:~!#%^&*()=+[]{}\\<>|?/\"\t\v\n\r\f "); while (new_word != NULL) { string temp = string(new_word); cout << temp << endl; new_word = strtok(NULL, "-.,;:~!#%^&*()=+[]{}\\<>|?/\"\t\v\n\r\f "); } }
And how to convert a string into char ch[] ?
Thx and regard